package cn.edu.lzzy.mypractices.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Getter
@Setter
@AllArgsConstructor
public class Chapter extends BaseEntity {
    public String name;
    public String description;
    public boolean open;

    @Temporal(TemporalType.TIMESTAMP)
    public Date createTime;
    @Temporal(TemporalType.TIMESTAMP)
    public Date updateTime;

    @ManyToOne
    public Course course;

    public Chapter() {
        createTime = new Date();
        updateTime = createTime;
    }

    @OneToMany(mappedBy = "chapter")
    public List<Question> questions;

    @JsonBackReference
    public List<Question> getQuestions() {
        return questions;
    }

    @JsonBackReference
    public Course getCourse() {
        return course;
    }
}
